﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using Dapper;
using StructureMap;

namespace ConsoleApp.Dapper
{
    public class demo_dapper
    {
        public static void demo()
        {
            IContainer container = StructureMapIoc.Initialize();
            IDbConnection dbconn = ObjectFactory.GetInstance<IDbConnection>();

            DayRepository dayRepository = new DayRepository(dbconn);
            YearRepository yearRepository = new YearRepository(dbconn);

            Day day = new Day { DayName = "dayname1" };
            Year year = new Year { YearName = "yearname1" };

            dbconn.Open();
            IDbTransaction trans = dbconn.BeginTransaction();

            try
            {               
                dayRepository.Add(day);
                yearRepository.Add(year);

                trans.Commit();
            }
            catch 
            {
                trans.Rollback();
            }            
        }
    }
}